from flask import Flask, url_for, jsonify, request, send_from_directory, redirect
import json, glob
import numpy as np
import re, os
# from waitress import serve

app = Flask(__name__)

# @app.route('/', methods=['POST', 'GET'])
# def index():
    
#     # if request.method == 'POST':
#     # elif request.method == 'GET':
    
#     with open('./examples/webgl_lines_colors.html','r',encoding = "utf-8") as f:
#         read_buf = f.read()
#     return read_buf

@app.route("/up", methods=["POST"])
def upvote():
    with open('./mcom.txt', 'r', encoding = "utf-8") as f:
        buf = f.read()
    return buf

@app.route("/<path:path>")
def static_dirx(path):
    return send_from_directory("./", path)



# @app.route('/server')
# def server():
#     global html_col1, html_col2, html_col3, template
#     res = template.replace('FILL_EVERYTHING_HERE_COL1', html_col1)
#     res = res.replace('FILL_EVERYTHING_HERE_COL2', html_col2)
#     res = res.replace('FILL_EVERYTHING_HERE_COL3', html_col3)
#     Fig2233 = np.random.randint(low=3,high=5)
#     res = res.replace('FILL_2233_HERE', str(Fig2233))
#     TEXTURE = np.random.randint(low=0,high=157)
#     print('TEXTURE', TEXTURE)
#     res = res.replace('FILL_TEXTURE_HERE', str(TEXTURE))
#     return res



# @app.route('/browse/<path:filename>')
# def download_file(filename):
#     return send_from_directory(os.path.dirname(filename), os.path.basename(filename), as_attachment=True)

# @app.route("/assets/<path:path>")
# def static_dir(path):
#     return send_from_directory("assets", path)

# @app.route("/files/<path:path>")
# def static_dir2(path):
#     return send_from_directory("files", path)

# @app.route("/build/<path:path>")
# def static_dir3(path):
#     return send_from_directory("build", path)

# @app.route("/main.css")
# def static_file():
#     with open('./files/main.css','r',encoding = "utf-8") as f:
#         read_buf = f.read()
#     return read_buf

app.run(host='0.0.0.0', port=5050, debug=True)